package cqrtplm.mapper;

import cqrtplm.dto.CustomerPowerRecordModel;
import cqrtplm.dto.query.CustomerQueryDTO;
import cqrtplm.entity.RtCfgStatusInfoDO;
import cqrtplm.vo.ModuleVO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: zhengxiong.jiang
 * @createDate: 2025-10-24
 * @version: 1.0
 */
public interface CrmApiMapper {

    // 在 CrmApiMapper.java 中
    void getCustomerPowerRecordModels(
            Map<String, Object> params
    );

    @Select(" SELECT DISTINCT STATUSID,DEVCODE, PRODUCTTYPE, \n" +
            "       DBMS_LOB.SUBSTR(STATUSTITLE, 4000) AS STATUSTITLE, \n" +
            "       DBMS_LOB.SUBSTR(STATEDESCRIPTION, 4000) AS STATEDESCRIPTION, \n" +
            "       STATUSCODE\n" +
            "FROM (\n" +
            "    SELECT STATUSID,DEVCODE, PRODUCTTYPE, STATUSTITLE, STATEDESCRIPTION, STATUSCODE, \n" +
            "           ROW_NUMBER() OVER (ORDER BY DEVCODE) AS row_num\n" +
            "    FROM RT_CFG_STATUS_INFO\n" +
            "    WHERE STATUS = 1\n" +
            ")\n" +
            "WHERE row_num > 0 AND row_num <= 9999 ")
    List<RtCfgStatusInfoDO> selectStatusInfo();

    @Update("update RT_CFG_STATUS_INFO set OID=#{oid},OTYPE=#{otype} where STATUSID=#{statusid}")
    void updateOid(@org.apache.ibatis.annotations.Param("oid") BigInteger oid, @org.apache.ibatis.annotations.Param("otype") String otype,@org.apache.ibatis.annotations.Param("statusid") String statusid);

    @Select("SELECT MODULEID, MODULENAME, PRODUCTMANNAME " +
            "FROM DSPF_STATUS_MODULE")
    List<ModuleVO> selectModule();

    @Update("UPDATE DSPF_STATUS_MODULE SET MODULEID = #{masteredoid} WHERE MODULEID = #{moduleid} ")
    int updateModule(@Param("moduleid") String moduleid, @Param("masteredoid") String masteredoid);

    @Update("UPDATE RT_CFG_STATUSMODULEITEM SET \"ModuleID\" = #{masteredoid} WHERE \"ModuleID\" = #{moduleid}")
    int updateModuleitem(@Param("moduleid") String moduleid, @Param("masteredoid") String masteredoid);

    @Update("UPDATE RT_CFG_STATUSMODULEITEMSUB SET  \"ModuleID\" = #{masteredoid} WHERE  \"ModuleID\" = #{moduleid} ")
    int updateModuleitemsub(@Param("moduleid") String moduleid, @Param("masteredoid") String masteredoid);

    @Update("UPDATE RT_CFG_STATUS_INFO SET  MODULEID = #{masteredoid} WHERE  MODULEID = #{moduleid} ")
    int updateinfo(@Param("moduleid") String moduleid, @Param("masteredoid") String masteredoid);

    @Update("UPDATE RT_CFG_STATUS_INFODETAIL SET  MODULEID = #{masteredoid} WHERE  MODULEID = #{moduleid} ")
    int updateinfodetail(@Param("moduleid") String moduleid, @Param("masteredoid") String masteredoid);

    List<String> selectPartNumberAllProductSpectrum();

    List<String> selectModuleIdBydevCode(String devCode);


    String selectPartNumberBymasteredoid(String modulePartnumber);

    List<ModuleVO> selectproductManName();
}
